{{extend name="index/index" /}}

{{block name="main"}}
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <!-- page start-->
        <div class="row">
            <div class="col-lg-12">
                <section class="panel">
                    <header class="panel-heading">
                        礼物回收站
                    </header>
                    <form method="get" action="{{:url('admin/gift/trash')}}">
                        <span>搜索：</span>
                        <input type="text" name="search" value="" class="text-word">
                        <input type="submit" value="查询" class="text-but">
                    </form>
                    <table class="table table-striped border-top table-advance" id="sample_1">
                        <thead>
                        <tr>
                            <th>礼物ID</th>
                            <th class="hidden-phone">礼物名</th>
                            <th class="hidden-phone">礼物价格</th>
                            <th class="hidden-phone">礼物图标</th>
                            <th class="hidden-phone">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{volist name="list" id="v"}}
                        <tr class="odd gradeX">
                            <td>{{$v['id']}}</td>
                            <td class="hidden-phone">{{$v['name']}}</td>
                            <td class="hidden-phone">{{$v['price']}}</td>
                            <td class="center hidden-phone"><img src="/uploads/{{$v['icon']}}" width="30"></td>
                            <td class="hidden-phone">
                                <a class="btn-sm btn btn-round btn-danger del-btn-s" data-toggle="modal"
                                   href="#myModal2" data-id="{{$v['id']}}">
                                    彻底删除
                                </a>
                                <a data-id="{{$v['id']}}" data-status="{{$v['status']}}"
                                   class="btn-sm btn btn-round btn-warning reset-btn-s" data-toggle="modal"
                                   href="#myModal3">
                                    恢复
                                </a>
                            </td>
                        </tr>
                        {{/volist}}
                        </tbody>
                    </table>
                    {{$list->render()}}
                </section>
            </div>
        </div>
        <!-- page end-->

        <!--modal start-->
        <section class="panel">
            <!-- Modal -->
            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title">删除礼物</h4>
                        </div>
                        <div class="modal-body">
                            确认要彻底删除吗?
                        </div>
                        <div class="modal-footer">
                            <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                            <button data-dismiss="modal" class="btn btn-danger del-btn" type="button">删除</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- modal -->
            <!-- Modal -->
            <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title">恢复</h4>
                        </div>
                        <div class="modal-body">
                            确定要恢复该礼物吗?
                        </div>
                        <div class="modal-footer">
                            <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                            <button data-dismiss="modal" class="btn btn-danger reset-btn" type="button">确定</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- modal -->

        </section>
        <!--modal start-->
    </section>
</section>

<!--main content end-->
{{/block}}

{{block name="myjs"}}
<script>
    // 设置弹框参数
    toastr.options = {
        closeButton: true,//是否显示关闭按钮
        progressBar: true,//实现显示计时条
        timeOut: "3000",//自动关闭时间
        positionClass: "toast-bottom-left"//提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
//    toast-top-right  顶端右边
    };

    $(function () {
        // 点击删除按钮
        $('.del-btn-s').click(function () {
            del_id = $(this).attr('data-id');
            del_obj = $(this).parents('tr');
        })
        // 触发删除用户操作
        $('.del-btn').click(function () {
            // 要删除的行
            delAjax(del_id, del_obj);
        });

        // 点击禁用/解禁按钮
        $('.reset-btn-s').click(function () {
            reset_id = $(this).attr('data-id');
            reset_status = $(this).attr('data-status');
            reset_obj = $(this).parents('tr');

        });
        // 点击确定禁用/解禁按钮
        $('.reset-btn').click(function () {
            $.ajax({
                type: 'post',
                url: '/gift/reset',
                data: {
                    'id': reset_id,
                    'status': reset_status
                },
                dataType: 'json',
                success: function (data) {
                    toastr.success('成功!');
                    // 删除该行
                    reset_obj.remove();
                },
                error: function () {
                    toastr.error('失败!');
                }
            });
        })

    });


    function delAjax(id, obj) {
        console.log(id);
        $.ajax({
            type: 'post',
            url: '/gift/del',
            data: {'id': id},
            dataType: 'json',
            success: function (data) {
                if (data) {
                    toastr.success('删除成功');
                    // 将该行删除
                    obj.remove();
                } else {
                    toastr.error('删除失败');
                }
            },
            error: function () {
                toastr.error('删除失败');
            }
        });
    }


</script>
{{/block}}